//
//  CommentManagerController.m
//  shopping
//
//  Created by 徐双 on 2017/9/15.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "CommentManagerController.h"
#import "MyEvaluateManagerViewCell.h"
#import "MyEvaluateMangerViewController.h"
#import "MyEvaluateWithImageViewController.h"

@interface CommentManagerController ()<ZJScrollPageViewDelegate>

{

    NSString *name;
    NSString *userPhone;
    NSString *allCount;
    NSString *picCount;
    

}

@property (strong, nonatomic) MyEvaluateManagerViewCell *friendHeadView;

@property(strong, nonatomic)NSArray<NSString *> *titles;
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;





@end

@implementation CommentManagerController

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    [self creationData];
    
}
- (void)creationData{
  
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;

    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:@"1" forKey:@"type"];
    
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonAppraise networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==100) {
            
            NSMutableDictionary *dic = [returnData objectForKey:@"data"];
//            allCount = dic[@"count"];
//            picCount = [dic objectForKey:@"count1"];
            NSMutableDictionary *dicOfNa = [[NSMutableDictionary alloc] init];
            dicOfNa = [dic objectForKey:@"user"];
            
            _friendHeadView = [[NSBundle mainBundle] loadNibNamed:@"MyEvaluateManagerViewCell" owner:self options:nil].lastObject;
            
            _friendHeadView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 160);
            self.friendHeadView.userName.text =[dicOfNa objectForKey:@"userName"];
            
            NSString *urlN=manage(AP_HOST, [dicOfNa objectForKey:@"userPhoto"]);
            
            [_friendHeadView.userPhoto sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@""]];
            
            NSString *strCount = [NSString stringWithFormat:@"%d",[[dic objectForKey:@"count"] intValue]];
            
            
            
            _friendHeadView.count.text = strCount;
            NSString *strCount1 = [NSString stringWithFormat:@"%d", [[dic objectForKey:@"count1"] intValue]];
            
            _friendHeadView.count1.text = strCount1;
            
            [self.view addSubview:_friendHeadView];
            
            [hud removeFromSuperview];
            
            
        }
        
        else {
            
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            [hud removeFromSuperview];
            
            
        }
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        [hud removeFromSuperview];
        
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"评价管理"];

 
    
    
    //必要的设置, 如果没有设置可能导致内容显示不正常
    self.automaticallyAdjustsScrollViewInsets = NO;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.selectedTitleColor = getColor(@"E23C3C");
    style.scrollLineColor = getColor(@"E23C3C");
    style.segmentHeight = 42;
    self.titles = @[@"全部评价",
                    @"有图评价",
                    ];
    self.childVcs = [self setupChildVc];
    
    // 初始化
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 160, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64.0 - 160) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [scrollPageView setSelectedIndex:self.index animated:YES];
    scrollPageView.contentView.scrollView.scrollEnabled = YES;
    [self.view addSubview:scrollPageView];
    
    
   
   
}

#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (NSArray *)setupChildVc {
    
    MyEvaluateMangerViewController *vc1 = [MyEvaluateMangerViewController new];
    
    MyEvaluateWithImageViewController *vc2 = [MyEvaluateWithImageViewController new];
    
    
    
    NSArray *childVcs = [NSArray arrayWithObjects:vc1, vc2, nil];
    return childVcs;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        childVc = self.childVcs[index];
    }
    
    
    
    
    return childVc;
}






@end
